home *** CD-ROM | disk | FTP | other *** search
- Subject: v13i097: Renice program, patches for Plexus and Xenix
- Newsgroups: comp.sources.unix
- Sender: sources
- Approved: rsalz@uunet.UU.NET
-
- Submitted-by: "John F. Haugh II" <hadron!sundc!rpp386!jfh>
- Posting-number: Volume 13, Issue 97
- Archive-name: attrenice.pch
-
- R$ -
-
- The file xenix.pat will patch renice to work on SCO Xenix for a '386, while
- the sys5.pat file will produce a renice which works on Plexus' System V.
-
- How did I ever live without this command?
-
- - John.
- ----- 8=< - 8=< - 8=< - 8=< - 8=< - 8=< -------------------------- SNIP ---
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create:
- # sys5.pat
- # xenix.pat
- export PATH; PATH=/bin:/usr/bin:$PATH
- if test -f 'sys5.pat'
- then
- echo shar: "will not over-write existing file 'sys5.pat'"
- else
- cat << \SHAR_EOF > 'sys5.pat'
- *** renice.c.orig Thu Mar 3 11:01:09 1988
- --- renice.c Thu Mar 3 11:20:31 1988
- ***************
- *** 24,30
- #include <grp.h>
- #include <sys/types.h>
- #include <sys/param.h>
- - #include <sys/tune.h>
- #include <sys/proc.h>
- #include <nlist.h>
-
-
- --- 24,29 -----
- #include <grp.h>
- #include <sys/types.h>
- #include <sys/param.h>
- #include <sys/proc.h>
- #include <sys/var.h>
- #include <nlist.h>
- ***************
- *** 26,31
- #include <sys/param.h>
- #include <sys/tune.h>
- #include <sys/proc.h>
- #include <nlist.h>
-
-
-
- --- 25,31 -----
- #include <sys/types.h>
- #include <sys/param.h>
- #include <sys/proc.h>
- + #include <sys/var.h>
- #include <nlist.h>
-
-
- ***************
- *** 37,44
-
- char *progname;
-
- ! #define tuhiaddr (mysyms[0].n_value)
- ! #define procaddr (mysyms[1].n_value)
-
- struct nlist mysyms[] =
- {
-
- --- 37,44 -----
-
- char *progname;
-
- ! #define procaddr (mysyms[0].n_value)
- ! #define vaddr (mysyms[1].n_value)
-
- struct nlist mysyms[] =
- {
- ***************
- *** 42,49
-
- struct nlist mysyms[] =
- {
- ! { "tuhi", },
- ! { "proc", },
- { (char *)0, },
- };
-
-
- --- 42,49 -----
-
- struct nlist mysyms[] =
- {
- ! { "_proc", },
- ! { "_v", },
- { (char *)0, },
- };
-
- ***************
- *** 52,58
- int kmem;
- int myuid;
- int NPROC;
- ! static struct proc proc;
-
-
- void usage()
-
- --- 52,59 -----
- int kmem;
- int myuid;
- int NPROC;
- ! static struct proc proctab;
- ! static struct var v;
-
-
- void usage()
- ***************
- *** 109,116
- /* one-time setup of main data structures from the kernel */
- setup()
- {
- - struct tunable tune;
- -
- if ( (kmem=open("/dev/kmem", O_RDWR)) < 0 )
- {
- sprintf(buf, "%s: can't open /dev/kmem", progname);
-
- --- 110,115 -----
- /* one-time setup of main data structures from the kernel */
- setup()
- {
- if ( (kmem=open("/dev/kmem", O_RDWR)) < 0 )
- {
- sprintf(buf, "%s: can't open /dev/kmem", progname);
- ***************
- *** 124,133
- perror(buf);
- exit(1);
- }
- -
- - myuid = getuid();
- - setuid(myuid);
- -
- #ifdef DEBUG
- fprintf(stderr, "tuhi: 0x%08lx\n", tuhiaddr);
- #endif DEBUG
-
- --- 123,128 -----
- perror(buf);
- exit(1);
- }
- #ifdef DEBUG
- fprintf(stderr, "v: 0x%08lx\n", vaddr);
- #endif DEBUG
- ***************
- *** 129,135
- setuid(myuid);
-
- #ifdef DEBUG
- ! fprintf(stderr, "tuhi: 0x%08lx\n", tuhiaddr);
- #endif DEBUG
- kcopy((char *)&tune, tuhiaddr, (long) sizeof tune);
-
-
- --- 124,130 -----
- exit(1);
- }
- #ifdef DEBUG
- ! fprintf(stderr, "v: 0x%08lx\n", vaddr);
- #endif DEBUG
- kcopy((char *)&v, vaddr, (long) sizeof v);
-
- ***************
- *** 131,137
- #ifdef DEBUG
- fprintf(stderr, "tuhi: 0x%08lx\n", tuhiaddr);
- #endif DEBUG
- ! kcopy((char *)&tune, tuhiaddr, (long) sizeof tune);
-
- /* do indirection on the proc address, since it */
- /* is just a pointer in the kernel */
-
- --- 126,132 -----
- #ifdef DEBUG
- fprintf(stderr, "v: 0x%08lx\n", vaddr);
- #endif DEBUG
- ! kcopy((char *)&v, vaddr, (long) sizeof v);
-
- #ifdef DEBUG
- fprintf(stderr, "proc: 0x%08lx\n", procaddr);
- ***************
- *** 133,142
- #endif DEBUG
- kcopy((char *)&tune, tuhiaddr, (long) sizeof tune);
-
- - /* do indirection on the proc address, since it */
- - /* is just a pointer in the kernel */
- - kcopy((char *)&procaddr, procaddr, (long) sizeof procaddr);
- -
- #ifdef DEBUG
- fprintf(stderr, "proc: 0x%08lx\n", procaddr);
- #endif DEBUG
-
- --- 128,133 -----
- #endif DEBUG
- kcopy((char *)&v, vaddr, (long) sizeof v);
-
- #ifdef DEBUG
- fprintf(stderr, "proc: 0x%08lx\n", procaddr);
- #endif DEBUG
- ***************
- *** 141,147
- fprintf(stderr, "proc: 0x%08lx\n", procaddr);
- #endif DEBUG
-
- ! NPROC = tune.nproc;
-
- #ifdef DEBUG
- fprintf(stderr, "NPROC: %d\n", NPROC);
-
- --- 132,140 -----
- fprintf(stderr, "proc: 0x%08lx\n", procaddr);
- #endif DEBUG
-
- ! NPROC = v.v_proc;
- ! myuid = getuid();
- ! setuid(myuid);
-
- #ifdef DEBUG
- fprintf(stderr, "NPROC: %d\n", NPROC);
- ***************
- *** 195,201
-
- for ( i=0 ; i<NPROC ; ++i )
- {
- ! kcopy((char *)&proc,
- (long)&((struct proc *)procaddr)[i],
- (long)sizeof proc);
- if ( proc.p_pid == pid )
-
- --- 188,194 -----
-
- for ( i=0 ; i<NPROC ; ++i )
- {
- ! kcopy((char *)&proctab,
- (long)&((struct proc *)procaddr)[i],
- (long)sizeof proctab);
- if ( proctab.p_pid == pid )
- ***************
- *** 197,204
- {
- kcopy((char *)&proc,
- (long)&((struct proc *)procaddr)[i],
- ! (long)sizeof proc);
- ! if ( proc.p_pid == pid )
- {
- #ifdef DEBUG
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
-
- --- 190,197 -----
- {
- kcopy((char *)&proctab,
- (long)&((struct proc *)procaddr)[i],
- ! (long)sizeof proctab);
- ! if ( proctab.p_pid == pid )
- {
- #ifdef DEBUG
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
- ***************
- *** 202,208
- {
- #ifdef DEBUG
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
- ! i, proc.p_uid);
-
- fprintf(stderr, "Old p_nice was %d\n", proc.p_nice);
- #endif DEBUG
-
- --- 195,201 -----
- {
- #ifdef DEBUG
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
- ! i, proctab.p_uid);
-
- fprintf(stderr, "Old p_nice was %d\n", proctab.p_nice);
- #endif DEBUG
- ***************
- *** 204,210
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
- i, proc.p_uid);
-
- ! fprintf(stderr, "Old p_nice was %d\n", proc.p_nice);
- #endif DEBUG
-
- tmpnice = proc.p_nice;
-
- --- 197,203 -----
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
- i, proctab.p_uid);
-
- ! fprintf(stderr, "Old p_nice was %d\n", proctab.p_nice);
- #endif DEBUG
-
- tmpnice = proctab.p_nice;
- ***************
- *** 207,213
- fprintf(stderr, "Old p_nice was %d\n", proc.p_nice);
- #endif DEBUG
-
- ! tmpnice = proc.p_nice;
-
- if (relative)
- tmpnice += value;
-
- --- 200,206 -----
- fprintf(stderr, "Old p_nice was %d\n", proctab.p_nice);
- #endif DEBUG
-
- ! tmpnice = proctab.p_nice;
-
- if (relative)
- tmpnice += value;
- ***************
- *** 223,229
- fprintf(stderr, "New p_nice is %d\n", tmpnice);
- #endif DEBUG
-
- ! if ( myuid && (myuid != proc.p_uid || tmpnice<proc.p_nice) )
- {
- errno = EACCES;
- sprintf(buf, "%s: can't renice process %d", progname, pid);
-
- --- 216,222 -----
- fprintf(stderr, "New p_nice is %d\n", tmpnice);
- #endif DEBUG
-
- ! if ( myuid && (myuid != proctab.p_uid || tmpnice<proctab.p_nice) )
- {
- errno = EACCES;
- sprintf(buf, "%s: can't renice process %d", progname, pid);
- ***************
- *** 231,237
- return 1;
- }
-
- ! proc.p_nice = tmpnice;
-
- kwrite((long)&((struct proc *)procaddr)[i]
- + ( ((char *)&proc.p_nice) - (char *)&proc ),
-
- --- 224,230 -----
- return 1;
- }
-
- ! proctab.p_nice = tmpnice;
-
- kwrite((long)&((struct proc *)procaddr)[i]
- + ( ((char *)&proctab.p_nice) - (char *)&proctab ),
- ***************
- *** 234,242
- proc.p_nice = tmpnice;
-
- kwrite((long)&((struct proc *)procaddr)[i]
- ! + ( ((char *)&proc.p_nice) - (char *)&proc ),
- ! (char *)&proc.p_nice,
- ! (long)sizeof proc.p_nice);
- return 0;
- }
- }
-
- --- 227,235 -----
- proctab.p_nice = tmpnice;
-
- kwrite((long)&((struct proc *)procaddr)[i]
- ! + ( ((char *)&proctab.p_nice) - (char *)&proctab ),
- ! (char *)&proctab.p_nice,
- ! (long)sizeof proctab.p_nice);
- return 0;
- }
- }
- ***************
- *** 240,246
- return 0;
- }
- }
- -
- fprintf(stderr, "%s: process %d not found.\n", progname, pid);
-
- return 1;
-
- --- 233,238 -----
- return 0;
- }
- }
- fprintf(stderr, "%s: process %d not found.\n", progname, pid);
-
- return 1;
- SHAR_EOF
- fi
- if test -f 'xenix.pat'
- then
- echo shar: "will not over-write existing file 'xenix.pat'"
- else
- cat << \SHAR_EOF > 'xenix.pat'
- *** renice.c.orig
- --- renice.c
- **************
- *** 13,18
- * yours, I would appreciate being given the appropriate
- * amount of credit.
- * -=] Ford [=-
- ************************************************************/
-
- #include <stdio.h>
- --- 13,23 -----
- * yours, I would appreciate being given the appropriate
- * amount of credit.
- * -=] Ford [=-
- + *
- + *
- + * Modifications
- + * 3/3/88 Ported to Plexus Unix System V pigs!haugj@rpp386.uucp
- + * 3/3/88 Ported to SCO Xenix System V jfh@rpp386.uucp
- ************************************************************/
-
- #include <stdio.h>
- **************
- *** 23,29
- #include <grp.h>
- #include <sys/types.h>
- #include <sys/param.h>
- ! #include <sys/tune.h>
- #include <sys/proc.h>
- #include <nlist.h>
-
- --- 28,34 -----
- #include <grp.h>
- #include <sys/types.h>
- #include <sys/param.h>
- ! #include <sys/page.h>
- #include <sys/proc.h>
- #include <sys/var.h>
- #include <a.out.h>
- **************
- *** 25,31
- #include <sys/param.h>
- #include <sys/tune.h>
- #include <sys/proc.h>
- ! #include <nlist.h>
-
-
- extern long lseek();
- --- 30,37 -----
- #include <sys/param.h>
- #include <sys/page.h>
- #include <sys/proc.h>
- ! #include <sys/var.h>
- ! #include <a.out.h>
-
-
- extern long lseek();
- **************
- *** 36,43
-
- char *progname;
-
- ! #define tuhiaddr (mysyms[0].n_value)
- ! #define procaddr (mysyms[1].n_value)
-
- struct nlist mysyms[] =
- {
- --- 42,49 -----
-
- char *progname;
-
- ! #define procaddr (mysyms[0].xl_value)
- ! #define vaddr (mysyms[1].xl_value)
-
- struct xlist mysyms[] =
- {
- **************
- *** 39,45
- #define tuhiaddr (mysyms[0].n_value)
- #define procaddr (mysyms[1].n_value)
-
- ! struct nlist mysyms[] =
- {
- { "tuhi", },
- { "proc", },
- --- 45,51 -----
- #define procaddr (mysyms[0].xl_value)
- #define vaddr (mysyms[1].xl_value)
-
- ! struct xlist mysyms[] =
- {
- { 0,0,0,"_proc", },
- { 0,0,0,"_v", },
- **************
- *** 41,49
-
- struct nlist mysyms[] =
- {
- ! { "tuhi", },
- ! { "proc", },
- ! { (char *)0, },
- };
-
- char buf[BUFSIZ];
- --- 47,55 -----
-
- struct xlist mysyms[] =
- {
- ! { 0,0,0,"_proc", },
- ! { 0,0,0,"_v", },
- ! { 0,0,0,(char *)0, },
- };
-
- char buf[BUFSIZ];
- **************
- *** 51,57
- int kmem;
- int myuid;
- int NPROC;
- ! static struct proc proc;
-
-
- void usage()
- --- 57,64 -----
- int kmem;
- int myuid;
- int NPROC;
- ! static struct proc proctab;
- ! static struct var v;
-
-
- void usage()
- **************
- *** 108,115
- /* one-time setup of main data structures from the kernel */
- setup()
- {
- - struct tunable tune;
- -
- if ( (kmem=open("/dev/kmem", O_RDWR)) < 0 )
- {
- sprintf(buf, "%s: can't open /dev/kmem", progname);
- --- 115,120 -----
- /* one-time setup of main data structures from the kernel */
- setup()
- {
- if ( (kmem=open("/dev/kmem", O_RDWR)) < 0 )
- {
- sprintf(buf, "%s: can't open /dev/kmem", progname);
- **************
- *** 117,123
- exit(1);
- }
-
- ! if (nlist("/unix", mysyms))
- {
- sprintf(buf, "%s: can't nlist /unix", progname);
- perror(buf);
- --- 122,128 -----
- exit(1);
- }
-
- ! if (xlist("/xenix", mysyms))
- {
- sprintf(buf, "%s: can't xlist /xenix", progname);
- perror(buf);
- **************
- *** 119,125
-
- if (nlist("/unix", mysyms))
- {
- ! sprintf(buf, "%s: can't nlist /unix", progname);
- perror(buf);
- exit(1);
- }
- --- 124,130 -----
-
- if (xlist("/xenix", mysyms))
- {
- ! sprintf(buf, "%s: can't xlist /xenix", progname);
- perror(buf);
- exit(1);
- }
- **************
- *** 123,132
- perror(buf);
- exit(1);
- }
- -
- - myuid = getuid();
- - setuid(myuid);
- -
- #ifdef DEBUG
- fprintf(stderr, "tuhi: 0x%08lx\n", tuhiaddr);
- #endif DEBUG
- --- 128,133 -----
- perror(buf);
- exit(1);
- }
- #ifdef DEBUG
- fprintf(stderr, "v: 0x%08lx\n", vaddr);
- #endif DEBUG
- **************
- *** 128,134
- setuid(myuid);
-
- #ifdef DEBUG
- ! fprintf(stderr, "tuhi: 0x%08lx\n", tuhiaddr);
- #endif DEBUG
- kcopy((char *)&tune, tuhiaddr, (long) sizeof tune);
-
- --- 129,135 -----
- exit(1);
- }
- #ifdef DEBUG
- ! fprintf(stderr, "v: 0x%08lx\n", vaddr);
- #endif DEBUG
- kcopy((char *)&v, vaddr, (long) sizeof v);
-
- **************
- *** 130,136
- #ifdef DEBUG
- fprintf(stderr, "tuhi: 0x%08lx\n", tuhiaddr);
- #endif DEBUG
- ! kcopy((char *)&tune, tuhiaddr, (long) sizeof tune);
-
- /* do indirection on the proc address, since it */
- /* is just a pointer in the kernel */
- --- 131,137 -----
- #ifdef DEBUG
- fprintf(stderr, "v: 0x%08lx\n", vaddr);
- #endif DEBUG
- ! kcopy((char *)&v, vaddr, (long) sizeof v);
-
- #ifdef DEBUG
- fprintf(stderr, "proc: 0x%08lx\n", procaddr);
- **************
- *** 132,141
- #endif DEBUG
- kcopy((char *)&tune, tuhiaddr, (long) sizeof tune);
-
- - /* do indirection on the proc address, since it */
- - /* is just a pointer in the kernel */
- - kcopy((char *)&procaddr, procaddr, (long) sizeof procaddr);
- -
- #ifdef DEBUG
- fprintf(stderr, "proc: 0x%08lx\n", procaddr);
- #endif DEBUG
- --- 133,138 -----
- #endif DEBUG
- kcopy((char *)&v, vaddr, (long) sizeof v);
-
- #ifdef DEBUG
- fprintf(stderr, "proc: 0x%08lx\n", procaddr);
- #endif DEBUG
- **************
- *** 140,146
- fprintf(stderr, "proc: 0x%08lx\n", procaddr);
- #endif DEBUG
-
- ! NPROC = tune.nproc;
-
- #ifdef DEBUG
- fprintf(stderr, "NPROC: %d\n", NPROC);
- --- 137,145 -----
- fprintf(stderr, "proc: 0x%08lx\n", procaddr);
- #endif DEBUG
-
- ! NPROC = v.v_proc;
- ! myuid = getuid();
- ! setuid(myuid);
-
- #ifdef DEBUG
- fprintf(stderr, "NPROC: %d\n", NPROC);
- **************
- *** 195,201
-
- for ( i=0 ; i<NPROC ; ++i )
- {
- ! kcopy((char *)&proc,
- (long)&((struct proc *)procaddr)[i],
- (long)sizeof proc);
- if ( proc.p_pid == pid )
- --- 194,200 -----
-
- for ( i=0 ; i<NPROC ; ++i )
- {
- ! kcopy((char *)&proctab,
- (long)&((struct proc *)procaddr)[i],
- (long)sizeof proctab);
- if ( proctab.p_pid == pid )
- **************
- *** 197,204
- {
- kcopy((char *)&proc,
- (long)&((struct proc *)procaddr)[i],
- ! (long)sizeof proc);
- ! if ( proc.p_pid == pid )
- {
- #ifdef DEBUG
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
- --- 196,203 -----
- {
- kcopy((char *)&proctab,
- (long)&((struct proc *)procaddr)[i],
- ! (long)sizeof proctab);
- ! if ( proctab.p_pid == pid )
- {
- #ifdef DEBUG
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
- **************
- *** 202,208
- {
- #ifdef DEBUG
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
- ! i, proc.p_uid);
-
- fprintf(stderr, "Old p_nice was %d\n", proc.p_nice);
- #endif DEBUG
- --- 201,207 -----
- {
- #ifdef DEBUG
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
- ! i, proctab.p_uid);
-
- fprintf(stderr, "Old p_nice was %d\n", proctab.p_nice);
- #endif DEBUG
- **************
- *** 204,210
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
- i, proc.p_uid);
-
- ! fprintf(stderr, "Old p_nice was %d\n", proc.p_nice);
- #endif DEBUG
-
- tmpnice = proc.p_nice;
- --- 203,209 -----
- fprintf(stderr, "Found it! proc[%d], p_uid is %d\n",
- i, proctab.p_uid);
-
- ! fprintf(stderr, "Old p_nice was %d\n", proctab.p_nice);
- #endif DEBUG
-
- tmpnice = proctab.p_nice;
- **************
- *** 207,213
- fprintf(stderr, "Old p_nice was %d\n", proc.p_nice);
- #endif DEBUG
-
- ! tmpnice = proc.p_nice;
-
- if (relative)
- tmpnice += value;
- --- 206,212 -----
- fprintf(stderr, "Old p_nice was %d\n", proctab.p_nice);
- #endif DEBUG
-
- ! tmpnice = proctab.p_nice;
-
- if (relative)
- tmpnice += value;
- **************
- *** 223,229
- fprintf(stderr, "New p_nice is %d\n", tmpnice);
- #endif DEBUG
-
- ! if ( myuid && (myuid != proc.p_uid || tmpnice<proc.p_nice) )
- {
- errno = EACCES;
- sprintf(buf, "%s: can't renice process %d", progname, pid);
- --- 222,228 -----
- fprintf(stderr, "New p_nice is %d\n", tmpnice);
- #endif DEBUG
-
- ! if ( myuid && (myuid != proctab.p_uid || tmpnice<proctab.p_nice) )
- {
- errno = EACCES;
- sprintf(buf, "%s: can't renice process %d", progname, pid);
- **************
- *** 231,237
- return 1;
- }
-
- ! proc.p_nice = tmpnice;
-
- kwrite((long)&((struct proc *)procaddr)[i]
- + ( ((char *)&proc.p_nice) - (char *)&proc ),
- --- 230,236 -----
- return 1;
- }
-
- ! proctab.p_nice = tmpnice;
-
- kwrite((long)&((struct proc *)procaddr)[i]
- + ( ((char *)&proctab.p_nice) - (char *)&proctab ),
- **************
- *** 234,242
- proc.p_nice = tmpnice;
-
- kwrite((long)&((struct proc *)procaddr)[i]
- ! + ( ((char *)&proc.p_nice) - (char *)&proc ),
- ! (char *)&proc.p_nice,
- ! (long)sizeof proc.p_nice);
- return 0;
- }
- }
- --- 233,241 -----
- proctab.p_nice = tmpnice;
-
- kwrite((long)&((struct proc *)procaddr)[i]
- ! + ( ((char *)&proctab.p_nice) - (char *)&proctab ),
- ! (char *)&proctab.p_nice,
- ! (long)sizeof proctab.p_nice);
- return 0;
- }
- }
- **************
- *** 240,246
- return 0;
- }
- }
- -
- fprintf(stderr, "%s: process %d not found.\n", progname, pid);
-
- return 1;
- --- 239,244 -----
- return 0;
- }
- }
- fprintf(stderr, "%s: process %d not found.\n", progname, pid);
-
- return 1;
- SHAR_EOF
- fi
- exit 0
- # End of shell archive
-
-